﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using System.Data.OleDb;
using System.Configuration;
using System.Data.SQLite;

namespace WindowsFormsApplication1
{
    public partial class Form5 : Form
    {
        public Form5()
        {
            InitializeComponent();
        }

        SQLiteConnection conn;

        private void Form5_Load(object sender, EventArgs e)
        {
            string conString = ConfigurationManager.ConnectionStrings["myconn"].ConnectionString;
            conn = new SQLiteConnection(conString);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string uname = textBox1.Text;
            string upwd = textBox2.Text;
            string ssql = "select * from test_pwd where uname = @uname and upwd = @upwd";
            conn.Open();
            SQLiteCommand cmd = new SQLiteCommand(ssql, conn);
            cmd.Parameters.AddWithValue("@uname", uname);
            cmd.Parameters.AddWithValue("@upwd", upwd);

            SQLiteDataReader sdr = cmd.ExecuteReader();          

            try
            {
                //如果存在用户名和密码正确数据执行进入系统操作  
                if (sdr.Read())
                {
                    Form1 frm1 = new Form1();
                    this.Hide();
                    frm1.Show();
                }
                else
                {
                    MessageBox.Show("请输入正确的用户名和密码");
                }
            }
            catch (Exception msg)
            {
                throw new Exception(msg.ToString());  //处理异常信息  
            }
            finally
            {
                conn.Close();                    //关闭连接                  
            }  

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit(); 
        }

      
    }
}
